package com.runjian.rundo.iot.agent.iec104.codec.handler;

import com.runjian.rundo.iot.agent.iec104.consts.Ti;
import com.runjian.rundo.iot.agent.iec104.parser.frame.IIec104Frame;
import org.springframework.stereotype.Service;

import java.util.EnumMap;
import java.util.Map;

@Service
public class DefaultIIec104FrameStrategy implements IIec104FrameStrategy {
	private static final Map<Ti, InfoElementHandler> strategy = new EnumMap<>(Ti.class);

	static {
		strategy.put(Ti.M_ME_NC_1, new IIec104FrameHandlerFor13());
	}

	@Override
	public void handle(IIec104Frame aIec104Frame) {
		InfoElementHandler handler = strategy.get(aIec104Frame.getAsdu().getTi());
		if (handler != null) {
			handler.handle(aIec104Frame);
		}
	}
}
